package com.bestcem.xm.user.grpc.service.param;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;

import java.io.Serializable;

/**
 * 分页参数入参校验
 *
 * @author panyun <yun.pan@idiaoyan.com>
 * @version v1.0
 * @date 2022/1/23 21:14
 */
@Data
@JsonIgnoreProperties(value = {"offset"})
public class PageParam implements Serializable {
    /**
     * 页号
     */
    private Integer page;

    /**
     * 分页大小
     */
    private Integer size;


    public PageParam() {
        page = 1;
        size = 1000;
    }

    public PageParam(Integer page, Integer size) {
        setPage(page);
        setSize(size);
    }

    public void setPage(Integer page) {
        this.page = page > 0 ? page : 1;
    }

    public void setSize(Integer size) {
        if (size > 0 && size < 1000) {
            this.size = size;
        } else {
            this.size = 1000;
        }
    }

    public Integer getOffset() {
        return (page - 1) * size;
    }

    public Integer getPage() {
        return page;
    }

    public Integer getSize() {
        return size;
    }
}
